home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / dev / misc / icqsocket.lha / isdev / regnewuser.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-25  |  4.6 KB  |  179 lines

  1. /*
  2.  
  3. RegNewUser - Registers a new UIN.
  4.  
  5. */
  6.  
  7. #include "icqsocket.h"
  8. #include "icqsocket_pragmas.h"
  9.  
  10. #include <dos.h>
  11.  
  12. #include <clib/exec_protos.h>
  13.  
  14. #include <stdio.h>
  15.  
  16. struct ICQSocketBase *ICQSocketBase;
  17.  
  18. ICQHandle *ih=NULL;
  19.  
  20. struct Hook icqerror;
  21. struct Hook icquin;
  22. struct Hook icqloggedin;
  23. struct Hook ackuserinfo;
  24.  
  25. BOOL stop=FALSE;    // Set to TRUE when we're done
  26. char newpass[64];    // The Mirabilis' client is limited to 9 chars,
  27.             // but why should we care about that?
  28. ULONG ournewUIN=0;
  29.  
  30. char server[64];
  31.  
  32. char nick[64], first[64], last[64], email[64];
  33.  
  34. void __asm __saveds icquinfunc(register __a2 ULONG newuin)
  35. {
  36.     /* This function is called when the registration is completed */
  37.     
  38.     printf("New UIN : %ld\n", newuin);
  39.     printf("Password: %s\n", newpass);
  40.  
  41.     ournewUIN=newuin;
  42.  
  43.     stop=TRUE;    /* That's all we need, bye! */
  44. }
  45.  
  46. void __asm __saveds ackuserinfofunc()
  47. {
  48.     /* This function is called when the user info has been ack'ed */
  49.     printf("New user info set.\n");
  50.     stop=TRUE;
  51. }
  52.  
  53. void __asm __saveds icqerrorfunc(register __a2 ICQError *e)
  54. {
  55.     /* This is called when an error occurs */
  56.  
  57.     if(e->SokErr) {
  58.         printf("Socket error: %ld\n", e->SokErr);
  59.     }
  60.     if(e->ICQErr) {
  61.         printf("ICQSocket error: %ld\n", e->ICQErr);
  62.     }
  63.     if(e->Hdr) {
  64.         printf(" Ver: %04x\n", e->Hdr->Version);
  65.         printf(" Cmd: %04x\n", e->Hdr->Command);
  66.         printf(" UIN: %ld\n", e->Hdr->UIN);
  67.         printf(" Seq: %08x\n", e->Hdr->Seq);
  68.         printf(" SID: %08x\n", e->Hdr->SID);
  69.     }
  70.  
  71.     printf("The error is fatal, shutting down...\n");
  72.     stop=TRUE;
  73. }
  74.  
  75. void __asm __saveds icqloggedinfunc(register __a2 ICQLogin *l)
  76. {
  77.     /* This function is called when the login procedure has completed */
  78.     /* and this is where we send the user information for the new */
  79.     /* account. */
  80.  
  81.     printf("Logged in with the new account!\n");
  82.  
  83.     /* Send the user info, and make sure we are notified when it is */
  84.     /* recieved by the server. */
  85.  
  86.     is_Send(ih, &ackuserinfo, ISC_NewUserInfo, nick, first, last, email);
  87. }
  88.  
  89. void main(int ac, char *av[])
  90. {
  91.     /* Set up the hook function pointers */
  92.     icquin.h_Entry=(HOOKFUNC)icquinfunc;
  93.     icqerror.h_Entry=(HOOKFUNC)icqerrorfunc;
  94.     icqloggedin.h_Entry=(HOOKFUNC)icqloggedinfunc;
  95.     ackuserinfo.h_Entry=(HOOKFUNC)ackuserinfofunc;
  96.  
  97.     ICQSocketBase=(struct ICQSocketBase *)OpenLibrary("icqsocket.library", 1);
  98.     if(ICQSocketBase) {
  99.  
  100.         if(ac==2) {    /* An argument (any argument, but only one) will */
  101.                 /* turn on the debugging */
  102.             is_Debug(Output(), 0);    /* Set up filehandle for debugging */
  103.                         /* Pass NULL to disable debugging */
  104.         }
  105.  
  106.         printf("Which server do you wish to connect to? Default is icq.mirabilis.com.\n");
  107.  
  108.         printf("Server     >> "); gets(server);
  109.  
  110.         if(server[0]=='\0') strcpy(server, "icq.mirabilis.com");
  111.  
  112.         printf("Using server: \"%s\"\n", server);
  113.  
  114.         printf("Now I need some basic info to set up your new account:\n\n");
  115.  
  116.         printf("Password   >> "); gets(newpass);    /* max 9 chars */
  117.         printf("Nickname   >> "); gets(nick);        /* max 20 chars */
  118.         printf("First name >> "); gets(first);
  119.         printf("Last name  >> "); gets(last);
  120.         printf("EMail      >> "); gets(email);
  121.  
  122.         if((ih=is_InitA(0, NULL))) {
  123.             /* Initialise icqsocket for any UIN. */
  124.             /* UIN == 0 will not result in creating log/cfg files */
  125.             /* and is recommended when registering new UINs. */
  126.  
  127.             is_InstallHook(ih, IID_ERROR, &icqerror);
  128.             is_InstallHook(ih, IID_NEW_UIN, &icquin);
  129.  
  130.             if(is_RegNewUser(ih,
  131.                 ISS_Host,    server,
  132.                 ISS_Password,    newpass,
  133.                 TAG_DONE)==OK) {
  134.  
  135.                 printf("*** Waiting for server to respond - Press CTRL-F to abort ***\n");
  136.                 while(!(is_NetWait(ih, SIGBREAKF_CTRL_F)&SIGBREAKF_CTRL_F) && !stop);
  137.                 is_RegNewUserCleanUp(ih);
  138.             } else {
  139.                 printf("Can't create socket or connect, is TCP/IP running?\n");
  140.             }
  141.  
  142.             is_Free(ih);
  143.         } else {
  144.             printf("Error! Could not create ICQSocket Handle\n");
  145.         }
  146.  
  147.         stop=FALSE;
  148.  
  149.         /* Now, if the registration was successfull, you must log in */
  150.         /* using the new UIN and password to complete the registration. */
  151.  
  152.         if(ournewUIN!=0) {
  153.             if((ih=is_InitA(ournewUIN, NULL))) {
  154.  
  155.                 is_InstallHook(ih, IID_ERROR, &icqerror);
  156.                 is_InstallHook(ih, IID_LOGIN, &icqloggedin);
  157.  
  158.                 printf("Setting user info...\n");
  159.  
  160.                 if(is_Connect(ih, ISS_Host, server,  ISS_Password, newpass, TAG_DONE)==OK) {
  161.                     printf("*** Waiting for server to respond - Press CTRL-F to abort ***\n");
  162.                     while(!(is_NetWait(ih, SIGBREAKF_CTRL_F)&SIGBREAKF_CTRL_F) && !stop);
  163.                     is_Disconnect(ih);
  164.                 }
  165.  
  166.                 is_Free(ih);
  167.             } else {
  168.                 printf("Error! Could not create ICQSocket Handle\n");
  169.             }
  170.         }
  171.  
  172.         is_Debug(NULL, 0);    // Disable debugging, in case we turned it on...
  173.  
  174.         CloseLibrary((struct Library *)ICQSocketBase);
  175.     } else {
  176.         printf("Error! ICQSocket.library could not be opened!\n");
  177.     }
  178. }
  179.